import Vue from 'vue'
import App from './App.vue'
import { router } from './router/index';
import { appRouter } from './router/router';
import store from "./store" //vuex
import iView from 'iview';
import 'iview/dist/styles/iview.css';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
// import "../theme/theme/index.css";
import 'element-ui/lib/theme-chalk/display.css';
import global from "@/utils/global" //全局方法
import './assets/date-format.js'
import Highcharts from 'highcharts/highstock';
import HighchartsMore from 'highcharts/highcharts-more';
import HighchartsDrilldown from 'highcharts/modules/drilldown';
import Highcharts3D from 'highcharts/highcharts-3d';
import Highmaps from 'highcharts/modules/map';
import Constants from "@/utils/constants"
import Router from 'vue-router'
import VueI18n from 'vue-i18n'
import ImagePreview from "@/components/Common/CImagePreview.vue"
import ErpImage from "@/components/Common/ErpImage.vue"
import NoData from "@/components/Common/NoData.vue"
import CopyText from "@/components/Common/CCopyText.vue"
Vue.prototype.$gt0 = function (rule, value, callback) {
    // 自定义验证规则函数，验证是否为大于0的数字
    const numValue = parseFloat(value);
    if (!isNaN(numValue) && numValue > 0) {
        callback(); // 验证通过
    } else {
        callback(new Error(rule.message)); // 验证不通过
    }
}

//linjm这里入侵一下
//Vue.prototype.$newCroHost = "http://8.142.6.55:18281/admin";
//Vue.prototype.$newCroHost = "http://localhost:8281/admin";
//linjm这里入侵一下

Vue.use(VueI18n)
Vue.use(Router)
HighchartsMore(Highcharts)
HighchartsDrilldown(Highcharts);
Highcharts3D(Highcharts);
Highmaps(Highcharts);

Vue.use(ElementUI);
Vue.use(iView);
Vue.use(global);
Vue.config.productionTip = false;
Vue.component("ImagePreview", ImagePreview); //全局自定义组件
Vue.component("NoData", NoData);
Vue.component("ErpImage", ErpImage);
Vue.component("CopyText", CopyText);
Vue.filter('fixed', function (value, dod) {

    return parseFloat(value).toFixed(dod);
})
Vue.filter('long2date', function (lt) {
    if (!lt)
        return '';
    if (lt == '' || lt == null || lt < 0) return;
    var date = new Date(lt * 1000);
    return date.dateFormat('Y-m-d');
})
Vue.filter('long2datetime', function (lt) {
    if (!lt) return '';
    var date = new Date(lt * 1000);
    return date.dateFormat('Y-m-d H:i:s');
})
Vue.filter('tradeStatus', function (lt) {

    return Constants.tradeStatus[lt];
})
Vue.filter('toFixed', function (lt, nb) {

    if (!lt) return '0.00';

    return lt.toFixed(nb);
})




const i18n = new VueI18n({
    locale: 'zh_CH', // 默认语言 可以借助cookie来设置和获取本地语言环境 从而加载不同的语言文件
    messages: {
        'zh_CH': require('@/assets/lang/zh_CN'),
        'en': require('@/assets/lang/EN'),
        'vn': require("@/assets/lang/VN")
    }
})
new Vue({
    store,
    i18n,
    router,
    data: {
        currentPageName: ''
    },
    mounted() {

        // this.currentPageName = this.$route.name;
        // 显示打开的页面的列表
        this.$store.commit('setOpenedList');
        this.$store.commit('initCachepage');
        // 权限菜单过滤相关
        this.$store.commit('updateMenulist');
        // iview-admin检查更新

    },
    created() {
        let tagsList = [];
        appRouter.map((item) => {

            if (item.children.length <= 1) {
                tagsList.push(item.children[0]);
            } else {
                tagsList.push(...item.children);
            }
        });
        // debugger;
        this.$store.commit('setTagsList', tagsList);
    },
    render: h => h(App),
}).$mount('#app')